﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SALES_ORDER_ITEM_TO_APPITEM
// * CreateDate    : 2013/2/7 20:59:51
// * Creater       : SalesOrderItemToAppItemBs
// * LastChangeDate: 2013/2/7 20:59:51
// * LastChanger   : 2013/2/7 20:59:51
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sales
{
    /// <summary>
    /// SalesOrderItemToAppitem
    /// </summary>
    public partial class SalesOrderItemToAppitemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSalesOrderItemToAppitemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SalesOrderItemToAppitemEntity GetSalesOrderItemToAppitem(SalesOrderItemToAppitemEntity objSalesOrderItemToAppitemEntity)
        {
            return DataAccess.SelectSingle<SalesOrderItemToAppitemEntity>(objSalesOrderItemToAppitemEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSalesOrderItemToAppitemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertSalesOrderItemToAppitem(SalesOrderItemToAppitemEntity objSalesOrderItemToAppitemEntity)
        {
            return DataAccess.Insert(objSalesOrderItemToAppitemEntity);
        }

        public static bool InsertSalesOrderItemToAppitem(List<SalesOrderItemToAppitemEntity> objSalesOrderItemToAppitemEntityList)
        {
            return DataAccess.Insert(objSalesOrderItemToAppitemEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSalesOrderItemToAppitemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSalesOrderItemToAppitem(SalesOrderItemToAppitemEntity objSalesOrderItemToAppitemEntity)
        {
            return DataAccess.Update(objSalesOrderItemToAppitemEntity);
        }

        public static bool UpdateSalesOrderItemToAppitem(List<SalesOrderItemToAppitemEntity> objSalesOrderItemToAppitemEntityList)
        {
            return DataAccess.Update<SalesOrderItemToAppitemEntity>(objSalesOrderItemToAppitemEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSalesOrderItemToAppitemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSalesOrderItemToAppitem(SalesOrderItemToAppitemEntity objSalesOrderItemToAppitemEntity)
        {
            return DataAccess.Delete(objSalesOrderItemToAppitemEntity);
        }

        public static bool DeleteSalesOrderItemToAppitem(List<SalesOrderItemToAppitemEntity> objSalesOrderItemToAppitemEntityList)
        {
            return DataAccess.Delete<SalesOrderItemToAppitemEntity>(objSalesOrderItemToAppitemEntityList);
        }
        public static bool DeleteSalesOrderItemToAppItem(List<SalesOrderItemToAppitemEntity> objSalesOrderItemToAppitemEntityList, DataAccessBroker broker)
        {
            if (objSalesOrderItemToAppitemEntityList!=null &&objSalesOrderItemToAppitemEntityList.Count > 0)
            {
                foreach (SalesOrderItemToAppitemEntity entity in objSalesOrderItemToAppitemEntityList)
                {
                    string sql = "";
                    if (!string.IsNullOrEmpty(entity.OrderItemId) && !string.IsNullOrEmpty(entity.ApplicationItemId))
                    {
                        sql = @"DELETE FROM dbo.SALES_ORDER_ITEM_TO_APPITEM WHERE  
ORDER_ITEM_ID='" + entity.OrderItemId + "' AND APPLICATION_ITEM_ID='" + entity.ApplicationItemId + "'";
                    }
                    else if (string.IsNullOrEmpty(entity.ApplicationItemId))
                    {
                        sql = @"DELETE FROM dbo.SALES_ORDER_ITEM_TO_APPITEM WHERE  
ORDER_ITEM_ID='" + entity.OrderItemId + "'";
                    }
                    else if (string.IsNullOrEmpty(entity.OrderItemId))
                    {
                        sql = @"DELETE FROM dbo.SALES_ORDER_ITEM_TO_APPITEM WHERE 
APPLICATION_ITEM_ID='" + entity.ApplicationItemId + "'";
                    }
                    int i = broker.ExecuteSQL(sql);
                    if (i != 1)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
        
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSalesOrderItemToAppitemAll()
        {
            return DataAccess.SelectAllDataSet<SalesOrderItemToAppitemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<SalesOrderItemToAppitemEntity> GetSalesOrderItemToAppitemAllList()
        {
            return DataAccess.SelectAll<SalesOrderItemToAppitemEntity>();
        }
        #endregion
    }


}

